﻿<Window x:Class="WindowPlace.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WindowPlace"
        xmlns:ToolKit="http://schemas.microsoft.com/wpf/2008/toolkit"
        xmlns:TN="clr-namespace:WPFTaskbarNotifier;assembly=WPFTaskbarNotifier"
        Title="WindowPlace" SizeToContent="Height" Width="450" ResizeMode="CanMinimize"
        Closing="Window_Closing" ShowInTaskbar="True"
        Padding="10" Icon="/WindowPlace;component/Icons/view_sidetree.ico">
    <Window.CommandBindings>
        <CommandBinding Command="New"
                        CanExecute="New_CanExecute"
                        Executed="New_Executed"></CommandBinding>
        <CommandBinding Command="{x:Static local:MainWindow.AddProfileCommand}"
                        Executed="AddProfile_Executed"
                        CanExecute="AddProfile_CanExecute"></CommandBinding>
        <CommandBinding Command="{x:Static local:MainWindow.RemoveProfileCommand}"
                        Executed="RemoveProfile_Executed"
                        CanExecute="RemoveProfile_CanExecute"></CommandBinding>
        <CommandBinding Command="{x:Static local:MainWindow.EditWindowInfoCommand}"
                        Executed="EditWindow_Executed"
                        CanExecute="EditWindow_CanExecute"></CommandBinding>
        <CommandBinding Command="{x:Static local:MainWindow.RemoveWindowInfoCommand}"
                        Executed="RemoveWindowInfo_Executed"
                        CanExecute="RemoveWindowInfo_CanExecute"></CommandBinding>
        <CommandBinding Command="Open"
                        Executed="Open_Executed"
                        CanExecute="Open_CanExecute"></CommandBinding>
        <CommandBinding Command="SaveAs"
                        Executed="SaveAs_Executed"
                        CanExecute="SaveAs_CanExecute"></CommandBinding>
        <CommandBinding Command="Refresh"
                        Executed="RefreshProfile_Executed"
                        CanExecute="RefreshProfile_CanExecute"></CommandBinding>
        <CommandBinding Command="{x:Static local:MainWindow.SetAllToCurrentPositionsCommand}"
                        Executed="SetAllToCurrentPositions_Executed"
                        CanExecute="SetAllToCurrentPositions_CanExecute"></CommandBinding>
        <CommandBinding Command="{x:Static local:MainWindow.SetToCurrentPositionCommand}"
                        Executed="SetToCurrentPosition_Executed"
                        CanExecute="SetToCurrentPosition_CanExecute"></CommandBinding>
        <CommandBinding Command="{x:Static local:MainWindow.RetrieveLostWindowCommand}"
                        Executed="RetrieveLostWindow_Executed"
                        CanExecute="RetrieveLostWindow_CanExecute"></CommandBinding>
        <CommandBinding Command="{x:Static local:MainWindow.StartAllWindowsCommand}"
                        Executed="StartAllWindows_Executed"
                        CanExecute="StartAllWindows_CanExecute"></CommandBinding>
    </Window.CommandBindings>



    <DockPanel LastChildFill="True" Margin="5">
        <TN:NotifyIcon x:Name="NotifyIcon" Text="WindowPlace" Icon="/WindowPlace;component/Icons/view_sidetree.ico"
                       MouseDoubleClick="NotifyIcon_MouseDoubleClick" DockPanel.Dock="Top">
        </TN:NotifyIcon>
        <Grid DockPanel.Dock="Top">
            <TextBlock Text="WindowPlace"
                           FontWeight="Bold" FontSize="18" Foreground="RoyalBlue" 
                       FontStyle="Italic"
                   Margin="5,2">
                <TextBlock.Effect>
                    <DropShadowEffect Opacity="0.2"></DropShadowEffect>
                </TextBlock.Effect>
            </TextBlock>
            <TextBlock Text="developed by Peter S. Freestone" HorizontalAlignment="Right"
                       VerticalAlignment="Bottom" Foreground="Gray"></TextBlock>
            <TextBlock Text="{Binding Settings.Version}" HorizontalAlignment="Right" FontStyle="Italic" Foreground="RoyalBlue" FontSize="8"></TextBlock>
        </Grid>
        <GroupBox DockPanel.Dock="Top" Header="Profiles" Padding="1">
            <StackPanel>
                <ListBox ItemsSource="{Binding PlaceProfiles}"
                         SelectedItem="{Binding SelectedPlaceProfile}"
                         ItemTemplate="{StaticResource PlaceProfileTemplate}"
                         ItemContainerStyle="{StaticResource ContainerStyle}"
                         Visibility="{Binding HasPlaceProfiles, Converter={StaticResource BoolToVisibility}}">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"></StackPanel>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ContextMenu>
                        <ContextMenu>
                            <MenuItem Command="{x:Static local:MainWindow.AddProfileCommand}" Header="Add"
                              CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}">
                                <MenuItem.Icon>
                                    <Image Source="/WindowPlace;component/icons/bt_add.png" Height="15"></Image>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Command="{x:Static local:MainWindow.RemoveProfileCommand}"
                                      CommandParameter="{Binding SelectedPlaceProfile}"
                                      Header="Remove">
                                <MenuItem.Icon>
                                    <Image Source="/WindowPlace;component/icons/bt_delete.png" Height="15"></Image>
                                </MenuItem.Icon>
                            </MenuItem>
                            <Separator></Separator>
                            <MenuItem Command="Refresh"
                                      CommandParameter="{Binding SelectedPlaceProfile}"
                                      Header="Refresh">
                                <MenuItem.Icon>
                                    <Image Source="/WindowPlace;component/icons/quick_restart.png" Height="15"></Image>
                                </MenuItem.Icon>
                            </MenuItem>
                            <MenuItem Command="{x:Static local:MainWindow.SetAllToCurrentPositionsCommand}"
                                      CommandParameter="{Binding SelectedPlaceProfile}"
                                      Header="Set All WindowInfos Positions">
                                <MenuItem.Icon>
                                    <Image Source="/WindowPlace;component/icons/view_sidetree.ico" Height="15"></Image>
                                </MenuItem.Icon>
                            </MenuItem>
                            <Separator></Separator>
                            <MenuItem Command="{x:Static local:MainWindow.StartAllWindowsCommand}"
                                      CommandParameter="{Binding SelectedPlaceProfile}"
                                      Header="Start all Windows (if not already Started)">
                                <MenuItem.Icon>
                                    <Image Source="/WindowPlace;component/icons/bt_play.png" Height="15"></Image>
                                </MenuItem.Icon>
                            </MenuItem>
                        </ContextMenu>
                    </ListBox.ContextMenu>
                </ListBox>
                <Button Padding="5,1" Margin="2"
                            Command="{x:Static local:MainWindow.AddProfileCommand}"
                            Visibility="{Binding NoPlaceProfiles, Converter={StaticResource BoolToVisibility}}"
                        ToolTip="Add a New Profile">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/WindowPlace;component/icons/bt_add.png" Height="15"></Image>
                        <TextBlock Text="Add Profile" VerticalAlignment="Center" FontWeight="Bold" Margin="5,2"></TextBlock>
                    </StackPanel>

                </Button>
                <Expander Header="Active Profile" Name="ActiveProfileGroupBox" Padding="-1">
                    <Expander.Style>
                        <Style TargetType="Expander">
                            <Setter Property="Visibility"
                    Value="Visible" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding SelectedPlaceProfile}"
                             Value="{x:Null}">
                                    <Setter Property="Visibility"
                            Value="Collapsed" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Expander.Style>
                    <StackPanel>
                        <DockPanel LastChildFill="True">
                            <TextBlock Text="Label" Margin="2,2,4,2" VerticalAlignment="Center"></TextBlock>
                            <TextBox Text="{Binding SelectedPlaceProfile.Label, UpdateSourceTrigger=PropertyChanged}" FontWeight="Bold"
                                     ToolTip="Edit the Label of the Active Profile"></TextBox>
                        </DockPanel>
                        <ListBox x:Name="DesiredWindowCaptionsList" DockPanel.Dock="Bottom"
                                 Margin="0,2"
                                 SelectedItem="{Binding SelectedDesiredWindowInfo}"
                                 ItemsSource="{Binding SelectedPlaceProfile.WindowInfos}"
                                 ItemTemplate="{StaticResource DesiredWindowInfoTemplate}"
                                 Background="LightSteelBlue"
                                 ItemContainerStyle="{StaticResource ContainerStyle}">
                        </ListBox>
                    </StackPanel>
                </Expander>


            </StackPanel>
        </GroupBox>
        <Expander Header="Options" Padding="-1" >

            <StackPanel >
                <GroupBox Header="Available Windows" DockPanel.Dock="Top" Margin="0">
                    <StackPanel>
                        <Button Padding="10,2" Margin="5" Click="GetWindowCaptions_Click"
                                ToolTip="Refresh the Window List">
                            <StackPanel Orientation="Horizontal">
                                <Image Source="/WindowPlace;component/icons/application.png" Height="15"></Image>
                                <TextBlock Text="Refresh Window List" VerticalAlignment="Center" FontWeight="Bold" Margin="5,2"></TextBlock>
                            </StackPanel>
                        </Button>
                        <ListBox x:Name="WindowCaptionsList" DockPanel.Dock="Bottom"
                                 SelectedItem="{Binding SelectedWindowInfo}"
                                 ItemTemplate="{StaticResource WindowInfoTemplate}"
                                 ScrollViewer.VerticalScrollBarVisibility="Visible"
                                 Height="200"
                                 ItemContainerStyle="{StaticResource ContainerStyle}"
                                 ToolTip="Right-click for more Options">
                            <ListBox.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Command="ApplicationCommands.New"
                                            CommandParameter="{Binding SelectedWindowInfo}" 
                                              Header="Add"
                                              ToolTip="Add this WindowInfo to all Profiles"
                                            CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}">
                                        <MenuItem.Icon>
                                            <Image Source="/WindowPlace;component/icons/bt_add.png" Height="15"></Image>
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <MenuItem Command="{x:Static local:MainWindow.RetrieveLostWindowCommand}"
                                                CommandParameter="{Binding SelectedWindowInfo}"
                                              CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}"
                                                ToolTip="Retrieve a Window that has gone off the screen"
                                                Header="Retrieve">
                                        <MenuItem.Icon>
                                            <Image Source="/WindowPlace;component/icons/find.png" Height="15"></Image>
                                        </MenuItem.Icon>
                                    </MenuItem>
                                </ContextMenu>
                            </ListBox.ContextMenu>
                        </ListBox>
                    </StackPanel>
                </GroupBox>
                <GroupBox Header="Settings" Padding="1"
                          >
                    <StackPanel>
                        <TextBlock Text="{Binding Settings.LastSession, StringFormat='Last Session: {0:G}'}"
                            FontStyle="Italic" Margin="0,2"></TextBlock>
                        <TextBox Text="{Binding SettingsFilename}" FontWeight="Bold" IsReadOnly="True"
                                ToolTip="Right-click to Open and Save As the Settings File">
                            <TextBox.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Command="Open" Header="Open..."
                                  CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}">
                                        <MenuItem.Icon>
                                            <Image Source="/WindowPlace;component/icons/files.png" Height="15"></Image>
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <MenuItem Command="SaveAs" Header="Save As..."
                                  CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContextMenu}}}">
                                        <MenuItem.Icon>
                                            <Image Source="/WindowPlace;component/icons/save.png" Height="15"></Image>
                                        </MenuItem.Icon>
                                    </MenuItem>
                                </ContextMenu>
                            </TextBox.ContextMenu>
                        </TextBox>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Startup wait time (ms)" VerticalAlignment="Center" Margin="2"></TextBlock>
                            <TextBox Text="{Binding Settings.StartupWaitTime}" VerticalAlignment="Center" Margin="5,2" Width="50"></TextBox>
                        </StackPanel>
                        <GroupBox Header="Hot Key">
                            <WrapPanel Orientation="Horizontal" HorizontalAlignment="Center">
                                <CheckBox IsChecked="{Binding Settings.PlusShift}" Margin="40,1">Shift</CheckBox>
                                <CheckBox IsChecked="{Binding Settings.PlusAlt}" Margin="40,1">Alt</CheckBox>
                                <CheckBox IsChecked="{Binding Settings.PlusControl}" Margin="40,1">Control</CheckBox>
                            </WrapPanel>
                        </GroupBox>
                    </StackPanel>
                </GroupBox>
            </StackPanel>
        </Expander>
    </DockPanel>
</Window>
